package com.yanwq.sayhi.controller.chat.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yanwq.sayhi.R;
import com.yanwq.sayhi.dao.bean.Chat;

import java.util.List;

/**
 * 作者：yanweiqiang。
 * 日期：2016/6/30 0030。
 */
public class ChatAdapter extends BaseAdapter {
    private List<Chat> mChatList;

    @Override
    public int getCount() {
        return mChatList.size();
    }

    @Override
    public Object getItem(int position) {
        return mChatList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return mChatList.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Context context = parent.getContext();
        ViewHolder holder = null;

        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_chat, parent, false);
            holder.avatar = (ImageView) convertView.findViewById(R.id.chat_avatar);
            holder.name = (TextView) convertView.findViewById(R.id.chat_name);
            holder.content = (TextView) convertView.findViewById(R.id.chat_content);
            holder.time = (TextView) convertView.findViewById(R.id.chat_time);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }



        return convertView;
    }

    private class ViewHolder {
        ImageView avatar;
        TextView name;
        TextView content;
        TextView time;
    }
}
